// HTTP Request Type
var CASE_PUBLISH = "CASE_PUBLISH";
var CASE_REVOKE = "CASE_REVOKE";
var CASE_DELETE = "CASE_DELETE";


function loadSucCaseList() {

	$("#casePageForm_publishStatus").combobox({
		panelHeight : 145,
		data : getAllCasePublishStatusData(),
		value : 0
	});

	$("#caseList").datagrid({
		// title:'查询申请管理',
		fit : true,
		striped : true,// 设置为true将交替显示行背景
		border : false,
		fitColumns : true,
		nowrap : false,
		loadMsg : "正在加载中。。。",
	    columns: [[
			    { field: 'caseName', title: '案例', width: 140,align:'center' },
	   			{ field: 'content', title: '案例内容', width: 260,align:'center' },
	   			{ field: 'publishDate', title: '发布日期', width: 60,align:'center' },
	   			{ field: 'publishStatus', title: '发布状态', width: 40,align:'center', formatter:publishStatusFormatter },
	   			{ field: 'publish', title: '管理', width: 60,align:'center', formatter:actionPublishFormatter },
	   			{ field: 'comment', title: '留言', width: 60,align:'center', formatter:actionCommentFormatter },
	   			{ field: 'edit', title: '操作', width: 30,align:'center', formatter:actionDeleteFormatter }
       ]],
       rownumbers : true, // 行号
	   singleSelect : true, // 是否单选
	   pagination : true,// 分页控件
	   pageSize : 20,
	   onLoadSuccess : onLoadSuccess
	});
	queryCase(1, 20);
	$(".panel-tool").hide();
}
// 查询申请管理列表
function queryCase(pageNumber,pageSize){
	var applyPageForm =$("form[name='casePageForm']");
	var url ='LoadCaseList';
	var param =  $("form[name='casePageForm']").serialize();
	param += '&pageNumber='+pageNumber+"&pageSize="+pageSize+"&type=admin";
	loadDataGirdJson(url,param,'#caseList');
}

//重置后查询所有
function queryCaseDefault(){
	$("input[name='caseName']").val("");
	$("input[name='caseContent']").val("");
	$("#casePageForm_publishStatus").combobox("setValue", "0");
	queryCase(1,20);
}

function actionPublishFormatter(data,row,index){
	var v1 = "";
	v1 = "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" " +
			" onclick=\"manageCase('"+row.caseId+"' , '" + CASE_PUBLISH + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">发布</span></span></a>"
	v1 += "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" " +
		" onclick=\"manageCase('"+row.caseId+"' , '" + CASE_REVOKE + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">撤回</span></span></a>"
	
	return v1;
}

function actionCommentFormatter(data,row,index){
	var v1 = "";
	v1 = "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" "
		+ " onclick=\"loadSpecifiedCommentPage('" + row.caseId + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">进入留言</span></span></a>"
	
	return v1;
}

function actionDeleteFormatter(data, row, index) {
	var v1 = "";
	v1 = "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" "
			+ " onclick=\"manageCase('" + row.caseId + "' , '" + CASE_DELETE + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">删除</span></span></a>"
	
	return v1;
}

function publishStatusFormatter(data, row, index) {
	var intStatus = row.publishStatus;
	
	if(intStatus == 0)
		return "未发布";
	else if(intStatus == 1)
		return "已发布";
	else
		return "未知";
}

function manageCase(caseId, manageType){
	$.post("ManageCase", {caseId : caseId, manageType : manageType}, function(text) {
		var data = (new Function("return "+text))();
		alert(data.status);
		if (data.status.indexOf('成功')) {
			queryCase(1, 20);
		}
	});
}

//打开新增案例界面
function openSubmitCaseWindow() {
	var diyColumnWindow = {
		id : 'submitCaseWindow',
		width : 420,
		height : 320,
		title : '新增案例窗口',
		url : 'submitCase.jsp',
		collapsible : false,
		minimizable : false,
		maximizable : false,
		resizable : false,
		closable : true,
		param : {
			callback : function() {
				//$("#submitCaseWindow").window("close");
			}
		}
	};
	OpenNewWindow(diyColumnWindow);
}

//进入指定留言界面
function loadSpecifiedCommentPage(currentCaseId) {
	$currentCaseId = currentCaseId;
	$('#centerPanel').panel({
	    href:'commentList.jsp',
	    onLoad:loadSucCommentList
	}); 
}